package org.example.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.pojo.LoveDiary;

import java.util.List;

/**
 * @author LENOVO
 * @description 针对表【love_diary(恋爱日记表)】的数据库操作Mapper
 * @createDate 2024-04-03 15:48:25
 * @Entity org.example.pojo.LoveDiary
 */
@Mapper
public interface LoveDiaryMapper {

    int deleteByPrimaryKey(Long id);

    int insert(LoveDiary record);

    int insertSelective(LoveDiary record);

    LoveDiary selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(LoveDiary record);

    int updateByPrimaryKey(LoveDiary record);

    @Insert("insert into love_diary(common_id, title, content, mood, image_url, created_at, modified_at) values " +
            "(#{userId},#{title},#{content},#{mood},#{url},now(),now())")
    void add(String title, String content, String mood, Integer userId, String url);

    @Update("update love_diary set image_url=#{url} where id=#{id}")
    void addPhoto(Integer id, String url);

    @Select("select * from love_diary where common_id=#{userId}")
    List<LoveDiary> list(Integer userId);

    @Update("update love_diary set title=#{title},content=#{content},mood=#{mood},image_url=#{url},modified_at=now() where id=#{id}")
    void editLaveDiary(String id, String title, String content, String mood, String url);
}
